package com.gushuang.leetcode;

import java.util.HashSet;
import java.util.Set;

public class longestConsecutiveSequence {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        for (int num : nums) {
            set.add(num);
        }
        int maxLen = 0;
        for (Integer num : set) {
            int len = 0;
            int count = num;
            if (!set.contains(count - 1)) {
                while (set.contains(count++)) {
                   len++;
                }
            }
            maxLen= Math.max(maxLen,len);
        }
        return maxLen;
    }
}
